#include "pic.h"
#include "io.h"

/*init PIC*/
void pic_init(void){
	//disable interrupts, except the Slave PIC pin
	outb(M_PIC_DIS, M_PIC_D);
	outb(S_PIC_DIS, S_PIC_D);
	
	//ICW1
	outb(PIC_ICW1, M_PIC_C);
	pic_wait();
	outb(PIC_ICW1, S_PIC_C);
	pic_wait();
	
	//ICW2 remap interrupts
	outb(IRQ0_BUFF, M_PIC_D);
	pic_wait();
	outb(IRQ8_BUFF, S_PIC_D);
	pic_wait();
	
	//ICW3 cascade
	outb(PIC_ICW3_M, M_PIC_D);
	pic_wait();
	outb(PIC_ICW3_S, S_PIC_D);
	pic_wait();
	
	//ICW4
	outb(PIC_ICW4, M_PIC_D);
	pic_wait();
	outb(PIC_ICW4, S_PIC_D);
	pic_wait();
	
	//Enable interrupts
	outb(0x00, M_PIC_D);
	pic_wait();
	outb(0x00, S_PIC_D);
	pic_wait();
}

